package sql

/*import (
	"LogisticsPort/model"
	"database/sql"
	"fmt"
	"gorm.io/gorm"
)

func CheckErr(err error) {
	if err != nil {
		fmt.Printf("err:%v\n", err)
	}
}

func GetSales(db *sql.DB, id int) *model.Sales {
	sqlStr := "select * from sales " +
		"where id = ?"

	sales := new(model.Sales)
	row := db.QueryRow(sqlStr, id)
	//确保QueryRow之后调用Scan方法，否则持有的数据库链接不会被释放
	err := row.Scan(&sales.Id, &sales.UserId, &sales.ProductType, &sales.Code, &sales.Name, &sales.Number,
		&sales.Area, &sales.NumberPlate, &sales.ParkingLocation, &sales.LogisticsCompany, &sales.DriverPhone,
		&sales.Supplier, &sales.Customer, &sales.CustomerPhone, &sales.UnitPrice, &sales.Date)

	if err != nil {
		fmt.Printf("scan failed, err:%v\n", err)
		return sales
	}
	fmt.Println(*sales)
	return sales
}

func add(db *gorm.DB, sales *model.Sales) {
	db.Create(sales)
}

func Insert(db *sql.DB, sales *model.Sales) bool {
	//var time = time.Now().Format("2006-01-02 15:04")
	sqlStr := "insert into " +
		"sales(user_id,type,code,name,number,area,number_plate,parking_location," +
		"logistics_company,driver_phone,supplier,customer,customer_phone,unit_price,date) " +
		"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

	stmt, err := db.Prepare(sqlStr)
	if err != nil {
		fmt.Println(err)
		return false
	}
	ret, err := stmt.Exec(sales.UserId, sales.ProductType, sales.Code, sales.Name, sales.Number, sales.Area,
		sales.NumberPlate, sales.ParkingLocation, sales.LogisticsCompany, sales.DriverPhone, sales.Supplier,
		sales.Customer, sales.CustomerPhone, sales.UnitPrice, sales.Date)
	if err != nil {
		fmt.Println(err)
		return false
	}
	fmt.Println(ret)
	theId, err := ret.LastInsertId()
	if err != nil {
		fmt.Println("get lastInsert Id failed")
		return false
	}
	fmt.Printf("insert success, the id is %d.\n", theId)
	return true
}

func Delete(db *sql.DB, id int) int64 {
	sqlStr := "delete from sales " +
		"where id = ?"
	stmt, err := db.Prepare(sqlStr)
	if err != nil {
		fmt.Println(err)
		return 0
	}
	result, err := stmt.Exec(id)
	if err != nil {
		fmt.Println("删除行失败", err)
		return 0
	}
	num, err := result.RowsAffected()
	if err != nil {
		fmt.Println(err)
		return 0
	}
	return num
}

func update(db *sql.DB, sales *model.Sales) bool {
	sqlStr := "update sales set" +
		"user_id=?,type=?,code=?,name=?,number=?,area=?,number_plate=?,parking_location=?," +
		"logistics_company=?,driver_phone=?,supplier=?,customer=?,customer_phone=?,unit_price=?,date=?" +
		"where id = ?"

	stmt, err := db.Prepare(sqlStr)
	if err != nil {
		fmt.Println(err)
		return false
	}
	ret, err := stmt.Exec(sales.UserId, sales.ProductType, sales.Code, sales.Name, sales.Number, sales.Area,
		sales.NumberPlate, sales.ParkingLocation, sales.LogisticsCompany, sales.DriverPhone, sales.Supplier,
		sales.Customer, sales.CustomerPhone, sales.UnitPrice, sales.Date, sales.Id)
	if err != nil {
		fmt.Println(err)
		return false
	}
	fmt.Println(ret)
	theId, err := ret.LastInsertId()
	if err != nil {
		fmt.Println("get lastInsert Id failed")
		return false
	}
	fmt.Printf("insert success, the id is %d.\n", theId)
	return true
}
*/
